﻿package mortal.game.utils
{
    import Message.BroadCast.*;
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.events.*;
    import extend.language.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;

    public class GuildUtil extends Object
    {
        public static const MemberOnlineColor:uint = 16777215;
        public static const MemberOfflineColor:uint = 10066329;
        private static var _sortTypeMer:String;
        private static var _sortByAttribMer:String;

        public function GuildUtil()
        {
            return;
        }// end function

        public static function getMemberOfflineState(param1:Date) : String
        {
            var _loc_2:* = ClockManager.instance.nowDate.time - param1.time;
            if (_loc_2 >= 7 * 24 * 60 * 60 * 1000)
            {
                return Language.getString(20693);
            }
            if (_loc_2 >= 5 * 24 * 60 * 60 * 1000)
            {
                return Language.getString(20694);
            }
            if (_loc_2 >= 3 * 24 * 60 * 60 * 1000)
            {
                return Language.getString(20695);
            }
            return Language.getString(20696);
        }// end function

        public static function defaultMemberListSortFunc(param1:SGuildMember, param2:SGuildMember) : Number
        {
            if (param1.miniPlayer.online && !param2.miniPlayer.online)
            {
                return -1;
            }
            if (!param1.miniPlayer.online && param2.miniPlayer.online)
            {
                return 1;
            }
            if (param1.position > param2.position)
            {
                return -1;
            }
            if (param1.position < param2.position)
            {
                return 1;
            }
            if (param1.miniPlayer.combat > param2.miniPlayer.combat)
            {
                return -1;
            }
            if (param1.miniPlayer.combat < param2.miniPlayer.combat)
            {
                return 1;
            }
            return 0;
        }// end function

        public static function constructMemberListSortFunc(param1:String, param2:String, param3:Boolean = false) : Function
        {
            var sortByAttrib:* = param1;
            var sortType:* = param2;
            var isPlayerAttrib:* = param3;
            var sortFunction:* = function (param1:SGuildMember, param2:SGuildMember) : Number
            {
                if (!param1.miniPlayer.hasOwnProperty(sortByAttrib))
                {
                }
                switch(sortType)
                {
                    case SortEvent.ASCENDING:
                    {
                        if (param1.miniPlayer[sortByAttrib] > param2.miniPlayer[sortByAttrib])
                        {
                        }
                        if (param1.miniPlayer[sortByAttrib] < param2.miniPlayer[sortByAttrib])
                        {
                        }
                    }
                    case SortEvent.DESCENDING:
                    {
                        if (param1.miniPlayer[sortByAttrib] > param2.miniPlayer[sortByAttrib])
                        {
                        }
                        if (param1.miniPlayer[sortByAttrib] < param2.miniPlayer[sortByAttrib])
                        {
                        }
                    }
                    default:
                    {
                        break;
                    }
                }
                if (!param1.hasOwnProperty(sortByAttrib))
                {
                }
                switch(sortType)
                {
                    case SortEvent.ASCENDING:
                    {
                        if (param1[sortByAttrib] > param2[sortByAttrib])
                        {
                        }
                        if (param1[sortByAttrib] < param2[sortByAttrib])
                        {
                        }
                    }
                    case SortEvent.DESCENDING:
                    {
                        if (param1[sortByAttrib] > param2[sortByAttrib])
                        {
                        }
                        if (param1[sortByAttrib] < param2[sortByAttrib])
                        {
                        }
                    }
                    default:
                    {
                        break;
                    }
                }
                return 0;
            }// end function
            ;
            return sortFunction;
        }// end function

        public static function constructMercenaryListSortFunc(param1:String, param2:String, param3:Boolean = false) : Function
        {
            var _loc_4:Function = null;
            _sortTypeMer = param2;
            _sortByAttribMer = param1;
            if (param3)
            {
                _loc_4 = constructMercenarySort1;
            }
            else
            {
                _loc_4 = constructMercenarySort2;
            }
            return _loc_4;
        }// end function

        private static function constructMercenarySort1(param1:SGuildMercenary, param2:SGuildMercenary) : Number
        {
            if (!param1.hasOwnProperty(_sortByAttribMer))
            {
                return 0;
            }
            switch(_sortTypeMer)
            {
                case SortEvent.ASCENDING:
                {
                    if (param1[_sortByAttribMer] > param2[_sortByAttribMer])
                    {
                        return 1;
                    }
                    if (param1[_sortByAttribMer] < param2[_sortByAttribMer])
                    {
                        return -1;
                    }
                    return 0;
                }
                case SortEvent.DESCENDING:
                {
                    if (param1[_sortByAttribMer] > param2[_sortByAttribMer])
                    {
                        return -1;
                    }
                    if (param1[_sortByAttribMer] < param2[_sortByAttribMer])
                    {
                        return 1;
                    }
                    return 0;
                }
                default:
                {
                    break;
                }
            }
            return 0;
        }// end function

        private static function constructMercenarySort2(param1:SGuildMercenary, param2:SGuildMercenary) : Number
        {
            if (!param1.hasOwnProperty(_sortByAttribMer))
            {
                return 0;
            }
            switch(_sortTypeMer)
            {
                case SortEvent.ASCENDING:
                {
                    if (param1[_sortByAttribMer] > param2[_sortByAttribMer])
                    {
                        return 1;
                    }
                    if (param1[_sortByAttribMer] < param2[_sortByAttribMer])
                    {
                        return -1;
                    }
                    return 0;
                }
                case SortEvent.DESCENDING:
                {
                    if (param1[_sortByAttribMer] > param2[_sortByAttribMer])
                    {
                        return -1;
                    }
                    if (param1[_sortByAttribMer] < param2[_sortByAttribMer])
                    {
                        return 1;
                    }
                    return 0;
                }
                default:
                {
                    break;
                }
            }
            return 0;
        }// end function

        public static function constructMercenarySort3(param1:SGuildMercenary, param2:SGuildMercenary) : Number
        {
            if (!param1.hasOwnProperty(_sortByAttribMer))
            {
                return 0;
            }
            switch(_sortTypeMer)
            {
                case SortEvent.ASCENDING:
                {
                    if (param1.creatdt.time > param2.creatdt.time)
                    {
                        return 1;
                    }
                    if (param1.creatdt.time < param2.creatdt.time)
                    {
                        return -1;
                    }
                    return 0;
                }
                case SortEvent.DESCENDING:
                {
                    if (param1.creatdt.time > param2.creatdt.time)
                    {
                        return -1;
                    }
                    if (param1.creatdt.time < param2.creatdt.time)
                    {
                        return 1;
                    }
                    return 0;
                }
                default:
                {
                    break;
                }
            }
            return 0;
        }// end function

        public static function getGuildSkillConfigAttribute(param1:int) : String
        {
            var _loc_2:* = GuildSchoolConfig.instance.getInfoByLevel(int(GuildSchoolConfig.instance.maxKey));
            var _loc_3:* = ObjectParser.getClassVars(new TGuildSchoolTarget(), true);
            var _loc_4:* = SkillConfig.instance.getInfoById(param1).series;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_3.length)
            {
                
                if (_loc_3[_loc_5] == "schoolLevel")
                {
                }
                else if (SkillConfig.instance.getInfoById(_loc_2[_loc_3[_loc_5]]).series == _loc_4)
                {
                    return _loc_3[_loc_5];
                }
                _loc_5++;
            }
            return "";
        }// end function

        public static function getGuildWarStar(param1:int) : Number
        {
            var _loc_2:* = Number(param1 - 10000) / 2000;
            if (_loc_2 < 0)
            {
                _loc_2 = 0;
            }
            return _loc_2;
        }// end function

        public static function get roleBuff() : Array
        {
            var _loc_2:SBuffInfo = null;
            var _loc_1:Array = [];
            for each (_loc_2 in Cache.instance.role.entityInfo.buffInfos)
            {
                
                _loc_1.push(_loc_2.buffId);
            }
            return _loc_1;
        }// end function

        public static function getPosName(param1:int) : String
        {
            var _loc_2:* = GameDefConfig.instance.getItem("EGuildPostion", param1);
            return HTMLUtil.addColor(_loc_2.text, _loc_2.text1);
        }// end function

        public static function isInMyGuild(param1:int) : Boolean
        {
            var _loc_2:* = Cache.instance.guild.selfGuildInfo;
            return _loc_2 && _loc_2.guildID == param1;
        }// end function

        public static function canGetFruit() : Boolean
        {
            if (Cache.instance.guild == null || Cache.instance.guild.selfGuildInfo == null || Cache.instance.guild.selfGuildInfo.gardenInfo == null)
            {
                return false;
            }
            var _loc_1:* = ClockManager.instance.nowDate;
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.gardenInfo.nextPickUpDt;
            if (_loc_1.time >= _loc_2.time)
            {
                return true;
            }
            return false;
        }// end function

    }
}
